package test.serverframe.armc.server.manager.controller;

import io.swagger.annotations.*;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import test.serverframe.armc.server.manager.common.ResultDtoUtil;
import test.serverframe.armc.server.manager.domain.TaskEnterInterface;
import test.serverframe.armc.server.manager.dto.ResultDto;
import test.serverframe.armc.server.manager.model.CenterInterface;
import test.serverframe.armc.server.manager.service.*;

import javax.validation.Valid;
import java.util.Map;

@CrossOrigin(origins = "*")
@Api("接口参数操作")
@Validated
@RequestMapping()
@RestController
public class TaskEnterInterfaceController {
    /**
     * @param taskId
     * @return ResultDto<Object>
     * @throws JSONException
     */
    @Autowired
    LinkInterfaceService linkInterfaceService;

    @Autowired
    private CenterAPIService centerAPIService;
    @Autowired
    private TaskEnterInterfaceService taskEnterInterfaceService;
    @Autowired
    private ServerApiService serverApiService;
    @Autowired
    private TaskService taskService;

    /**
     * 获取父接口
     */
    public ResultDto<CenterInterface> findParentInterface() {

        return null;
    }

    @PostMapping(value = "/getresponse")
    @ApiOperation(notes = "根据接口ID和请求信息返回Response", value = "根据接口ID和请求信息返回Response", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "siaId", value = "接口ID", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "queryData", value = "queryStr", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "bodyData", value = "bodyStr", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "headerData", value = "headerStr", required = false)})
    public ResultDto<Object> getResponse(String siaId ,String queryData,String bodyData,String headerData) throws JSONException {
        ResultDto<Object> result;
        try {
            result = ResultDtoUtil.success(serverApiService.getInterfaceResponse(siaId,"",bodyData,headerData));
        } catch (Exception e) {
            result = ResultDtoUtil.error(500, "获取失败");
        }
        return result;
    }

//    public ResultDto<Map<String,Object>> getResponse(String taskId){
//        ResultDto<Map<String,Object>> result;
//
//
//
//
//
//
//        return n;
//    }

}
